package com.itheima.controller.admin;


import com.itheima.result.Result;
import com.itheima.utils.AliOssUtil;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/admin/common")
@Api(tags = "通用接口")
@Slf4j
public class CommonController {
    @Autowired
    private AliOssUtil aliOssUtil;
//
//    @Autowired
//    private MinioUtil minioUtil;
//    @Autowired
//    private StorageTemlete storageTemlete;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        String s = filename.substring(filename.lastIndexOf("."));
        String objectName = UUID.randomUUID().toString() + s;
        byte[] bytes = file.getBytes();
        String upload = aliOssUtil.upload(bytes, objectName);
        return Result.success(upload);
    }
//    @PostMapping("/upload")
//    public Result upload(MultipartFile file) throws IOException {
//        String filename = file.getOriginalFilename();
//        String s = filename.substring(filename.lastIndexOf("."));
//        String objectName = UUID.randomUUID().toString() + s;
//        byte[] bytes = file.getBytes();
//        String upload = minioUtil.upload(bytes, objectName);
//        return Result.success(upload);
//    }

//    @PostMapping("/upload")
//    public Result upload(MultipartFile file) throws IOException {
//        String upload = storageTemlete.upload(file);
//        return Result.success(upload);
//    }

}
